<template>
	<view class="mian">
	   <!-- #ifdef MP-WEIXIN -->
	   <navbar :bgColor="bgColor" :btnColors='btnColor' title="我的活动" :isGoBack="true" :isNotice="true" :visible="true" ></navbar>
	   <!-- #endif -->	
		<swiper class="tab-content"  duration="300" bindchange="changeTab" style="background-color: #fff;" :style="{'height':winHeight+'px'}"> 
		    <swiper-item>
		       	<scroll-view :scroll-y="true" class="new-list-box" @scrolltolower="allLoadMore" scroll-top="scrollTop" scroll-with-animation :refresher-enabled="true" refresher-threshold="80" refresher-default-style="white" refresher-background="white" :refresher-triggered="triggered" @refresherrefresh="onAllRefresh">
		        <view class="goods_list">
					<view class="flex flex-wrap">					
						<block  v-for="(item,index) in goodsList" :key="key">
							<view class="classify-cell-recom bg-white border-b pb-20" @tap="goDetails" :data-posid="item.id">
								<view class="act_image">
									<view v-if="item.is_save==0" class="act_end">
										<text>已结束</text>
									</view>
									<view v-if="item.is_save==1" class="act_end" style="background-color: #518FA0 ;">
										<text>倒计时{{item.day}}天</text>
									</view>
									<image class="grid-img-recom" :src="item.image"  mode="scaleToFill" ></image>
								</view>								
								<view class="cate-zt flex flex-direction mt-10"    style="justify-content: flex-start;">
									<view class="pl-20 pr-15 productNameText text-bold" style="font-size: 32rpx;">{{item.name}}</view>
									<view class="flex pl-20 pt-10">
										  <view class="tagg" v-for="(tags,index) in item.activity_tagss" :key="key" >{{tags}}</view>
									</view>
									<view class="flex pb-20 mt-15 pl-20 pr-20">
										<u-icon name="map-fill" color="#999999" size="14"></u-icon>
										<text class="productNameText active_info ml-15">地点：{{item.address}}</text>    
									</view>        
									 <view class="flex pb-20 pl-20 pr-20">		
										<u-icon name="clock-fill" color="#999999" size="13" style="margin-left: 6rpx;"></u-icon>
										<text class="productNameText active_info ml-15">时间：{{item.active_time}}</text>
									 </view>     
								</view> 
							</view>
						</block>             
					</view> 
				</view> 
		      </scroll-view>
		    </swiper-item>       
		  </swiper>  	
		</view>
</template>

<script>
	
	export default {
		components: {
			
		 },
		data() {
			return {
				...getApp().globalData.config,
				winHeight:0,
				goodsList:[],
				search:'',
				pageNo:1,
				triggered: false, // 下拉是否激活
				
			}
		},				 
		onLoad(options) {				
			let height = uni.getSystemInfoSync().windowHeight;
			this.winHeight = (height - 80)	
			this.goodsList=[]
			if(uni.getStorageSync('search')){
				this.search=uni.getStorageSync('search')
			}
			this._requestPageList(true);
		},		
		onShow() {			
		},	
		onHide(){ 
			
		},
		onUnload() {
		},
		methods: {	
			// 详情
			goDetails:function(options){	
				console.log(options)
				let goodsId=options.currentTarget.dataset.posid
				uni.navigateTo({
					url:"/pages/activity/info/index?activityId="+goodsId
				})
			},		
			
			//关闭右边信息
			close() {
			  this.show = false
			  // console.log('close');
			},
			
			//搜索
			search_sub(){
				this.pageNo=1
				this.goodsList=[]
				uni.setStorageSync('search','')
				this._requestPageList(true);
			},
			
			// 参数
		    _requestPageList(isLoadMore = false, callback) {
				console.log(isLoadMore)
		        if(!isLoadMore){
			        this.allTabList=[], // 全部
			        this.pageNo= 1
			    }
			    let opt = {			
			      pageNo :this.pageNo
			    }
			    if(this.search){
			      opt['search']=this.search
			    }	
				opt.token=uni.getStorageSync('userInfo').token,
			    this._requestPageListCom("virtualTaskList", opt, callback);
			},
			  // 列表接口
			_requestPageListCom(url, params, callback) {			
			    this.$http.active_list(params).then(res => {
			      if (res.resCode == "9999") {
			        let oldList = [];     
			        oldList = this.goodsList;       
			        const newGoodsList = res.data.activity_list
			        const allData = [...oldList, ...newGoodsList]     
			        this.goodsList=allData			        
			        if(callback && typeof callback === 'function'){
			          callback()
			        }
			      }
			    })
			},
			// 上拉加载  滚动到底部/右边时触发
			allLoadMore(e){
				console.log('上拉----')
				let _self = this;
				// if (this._allLoadMore) return
				this._allLoadMore = true;
				this.pageNo= ++_self.pageNo				
				this._requestPageList(true, () => {
				  _self._allLoadMore = false;
				});
			},
			
			// 下拉刷新接口
			onAllRefresh() {
			 // 开启下拉自定义样式
			 console.log('下拉----')
				this.triggered = true;
				this.goodsList=[]
				this.pageNo=1;
				this._requestPageList(false, () => {
					// 当处理完数据刷新后，wx.stopPullDownRefresh可以停止当前页面的下拉刷新
					this.triggered = false;
				});    
			}			
		}
	}
</script>

<style>
 @import "./index.css";
</style>
